<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>系统菜单_编辑</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="//cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css">

    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>dist/css/AdminLTE.css">
    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>dist/css/skins/_all-skins.css">

    <link rel="stylesheet" href="<?php echo STATIC_ADMIN; ?>dist/css/yc_style.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="//cdn.bootcss.com/html5shiv/3.7.3/html5shiv.js"></script>
  <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body class="hold-transition skin-blue">
<!-- Site wrapper -->
<div class="wrapper">

  <!-- main -->
  <div class="content-wrapper" style="margin: 0;">

      <!-- page title -->
    <section class="content-header">
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-gear"></i> 系统管理</a></li>
        <li><a href="#">系统菜单</a></li>
        <li class="active">编辑</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="alert alert-dismissible" role="alert" style="display: none;">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <strong>提示：</strong><span id="msg">消息</span>
        </div>

      <!-- Default box -->
      <div class="box box-info">
          <div class="box-header with-border">
              <h3 class="box-title">编辑菜单</h3>
          </div>

          <form class="form-horizontal" id="menu_add" name="menu_add" method="post" action="<?php echo site_url('system/Menu/save');?>">
              <input type="hidden" id="menu_id" name="menu_id" value="<?php echo $menu['menu_id'];?>">
              <div class="box-body">
                  <div class="form-group">
                      <label for="menu_name" class="col-sm-1 control-label">菜单名称</label>
                      <div class="col-sm-4">
                          <input class="form-control" id="menu_name" name="menu_name" type="text"
                                 datatype="*"
                                 nullmsg="菜单名称不能为空"
                                 errormsg="菜单名称不能为空"
                                 placeholder="菜单名称"
                                 value="<?php echo $menu['menu_name'];?>">
                      </div>
                  </div>

                  <div class="form-group">
                      <label for="menu_parentid" class="col-sm-1 control-label">上级菜单</label>
                      <div class="col-sm-4">
                          <select class="form-control" id="menu_parent" name="menu_parentid" onchange="formDisplay();">
                              <option value="0" <?php echo $menu['menu_parentid']==0 ? 'selected' : '';?>>≡ 作为一级菜单 ≡</option>
                              <?php
                              foreach ($menu_tree as $val) {
                                  if ($val['level']===0) { // 只显示一级菜单
                                      if ($menu['menu_parentid']==$val['menu_id']) {
                                          echo '<option value="' . $val['menu_id'] . '" selected>' . $val['menu_name'] . '</option>';
                                      } else {
                                          echo '<option value="' . $val['menu_id'] . '">' . $val['menu_name'] . '</option>';
                                      }
                                  }
                              }
                              ?>
                          </select>
                      </div>
                  </div>

                  <div class="form-group" id="menu_module_box">
                      <label for="menu_module" class="col-sm-1 control-label">模块目录</label>
                      <div class="col-sm-4">
                          <input class="form-control" id="menu_module" name="menu_module" type="text" placeholder="模块目录" value="<?php echo $menu['menu_module'];?>">
                          <div class="Validform_checktip">只允许为英文字母与下划线</div>
                      </div>
                  </div>

                  <div class="form-group" id="menu_controller_box">
                      <label for="menu_controller" class="col-sm-1 control-label">控制器</label>
                      <div class="col-sm-4">
                          <input class="form-control" id="menu_controller" name="menu_controller" type="text" placeholder="控制器" value="<?php echo $menu['menu_controller'];?>">
                      </div>
                  </div>

                  <div class="form-group" id="menu_action_box">
                      <label for="menu_action" class="col-sm-1 control-label">操作方法</label>
                      <div class="col-sm-4">
                          <input class="form-control" id="menu_action" name="menu_action" type="text" placeholder="操作方法" value="<?php echo $menu['menu_action'];?>">
                      </div>
                  </div>

                  <div class="form-group">
                      <label for="menu_status" class="col-sm-1 control-label">状态</label>
                      <div class="col-sm-1">
                          <select class="form-control" id="menu_status" name="menu_status">
                              <option value="1" <?php echo $menu['menu_status']==1 ? 'selected' : '';?>>正常</option>
                              <option value="0" <?php echo $menu['menu_status']==0 ? 'selected' : '';?>>隐藏</option>
                          </select>
                      </div>
                  </div>
              </div>

              <div class="box-footer">
                  <a href="<?php echo site_url('system/Menu/index');?>" class="btn btn-default" role="button">取消</a>
                  <button type="submit" class="btn btn-info pull-right">保存</button>
              </div>
          </form>
      </div>
      <!-- /.box -->

    </section>
    <!-- /.content -->
  </div>
  <!-- main end -->

</div>
<!-- ./wrapper -->

</body>
</html>
<!-- jQuery 2.2.3 -->
<script src="<?php echo STATIC_COMMON; ?>plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="<?php echo STATIC_ADMIN; ?>bootstrap/js/bootstrap.min.js"></script>
<!-- layer 3.0.3 -->
<script src="<?php echo STATIC_COMMON; ?>plugins/layer/layer.js"></script>

<!-- Validform 5.3.2 -->
<script src="<?php echo STATIC_COMMON; ?>plugins/Validform/Validform_v5.3.2.js"></script>

<!-- other -->
<script src="<?php echo STATIC_ADMIN; ?>dist/js/yc_app.js"></script>

<script>
    $(function() {
        formDisplay();

        ycApp.initValidator();
    });

    //表单项目显示控制
    function formDisplay() {
        var _this = $('option:selected', '#menu_parentid');

        var $menu_module = $('#menu_module_box'),
            $input1 = $menu_module.find('input');

        var $menu_controller = $('#menu_controller_box'),
            $input2 = $menu_controller.find('input');

        var $menu_action = $('#menu_action_box'),
            $input3 = $menu_action.find('input');
        if (_this.val()<=0) {
            $menu_module.hide();
            $input1.removeAttr('datatype');
            $input1.removeAttr('nullmsg');
            $input1.removeAttr('errormsg');

            $menu_controller.hide();
            $input2.removeAttr('datatype');
            $input2.removeAttr('nullmsg');
            $input2.removeAttr('errormsg');

            $menu_action.hide();
            $input3.removeAttr('datatype');
            $input3.removeAttr('nullmsg');
            $input3.removeAttr('errormsg');

        } else {
            $menu_module.show();
            $input1.attr({
                'datatype': 'yes_null|scope_string_1',
                'nullmsg': '模块目录不能为空',
                'errormsg': '方法名只允许为英文字母与下划线'
            });

            $menu_controller.show();
            $input2.attr({
                'datatype': '*,first_capital',
                'nullmsg': '控制器名不能为空',
                'errormsg': '控制器名只允许为英文字母，且首字母必须为大写'
            });

            $menu_action.show();
            $input3.attr({
                'datatype': '*,scope_string_1',
                'nullmsg': '方法名不能为空',
                'errormsg': '方法名只允许为英文字母与下划线'
            });
        }
    }
</script>
